//- Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. 
//- <https://www.chatopera.com>, Licensed under the Chunsong Public 
//- License, Version 1.0  (the "License"), https://docs.cskefu.com/licenses/v1.html
//- Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
//- Copyright (C) 2018-Jun. 2023 Chatopera Inc, <https://www.chatopera.com>
//- Licensed under the Apache License, Version 2.0
//- http://www.apache.org/licenses/LICENSE-2.0
extends /admin/include/layout.pug
block content
    .row: .col-lg-12
        h1.site-h1(style='background-color:#FFFFFF;')
            | 元数据列表 (#{metadataList.totalElements})
            span(style='float:right;')
                button.layui-btn.layui-btn-small.green(href='/admin/metadata/imptb.html', data-toggle='ajax', data-width='550', data-title='创建新字典项')
                    | 导入元数据
                a.layui-btn.layui-btn-small.layui-btn-danger#batdel(href='javascript:void(0)', data-toggle='tip', data-title='删除数据表项同时会删除数据表元数据下的所有内容，请确认是否继续操作”？', title='删除数据表')
                    | 批量删除
        .row(style='padding:5px;')
            .col-lg-12
                table.layui-table(lay-skin='line')
                    colgroup
                        col(width='1%')
                        col(width='25%')
                        col(width='15%')
                        col(width='10%')
                        col(width='24%')
                        col(width='15%')
                        col
                    thead
                        tr
                            th
                                input#all(type='checkbox', onclick='$(".ids").prop("checked" , $(this).prop("checked"));')
                            th 中文名
                            th 表名
                            th 类型
                            th ES数据
                            th 创建时间
                            th(style='white-space:nowrap;', nowrap) 操作
                    tbody
                        if size(metadataList.content) > 0
                            for table in metadataList.content
                                tr
                                    td(style="width:1%;"): input(type="checkbox", class="ids", name="ids", value=table.id)
                                    td: a(href="/admin/metadata/table.html?id=" + table.id)= table.name
                                    td= table.tablename
                                    td= (table.tabletype == "1") ? '数据表' : 'SQL'
                                    if table.fromdb == true
                                        td
                                            i.layui-icon(style="color:#19a55d;") &#xe618;
                                            span= uKeFuDic[table.listblocktemplet].name
                                            span= uKeFuDic[table.previewtemplet].name
                                    else
                                        td
                                    if table.createtime
                                        td= pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', table.createtime)
                                    else
                                        td
                                    td(style="white-space:nowrap;width:1%;", nowrap="nowrap")
                                        a(href="/admin/metadata/edit.html?id=" + table.id + "&p=" + (metadataList.number + 1), data-width="550", data-height="320", data-toggle="ajax", title="编辑" + table.name)
                                            i.layui-icon &#xe642;
                                            span 编辑
                                        a(href="/admin/metadata/delete.html?id=" + table.id + "&p=" + (metadataList.number + 1), data-toggle="tip" data-title="删除数据表项同时会删除数据表元数据下的所有内容，请确认是否删除数据表“" + table.name + "”？" title="删除" + table.name)
                                            i.layui-icon(style="color:red;") &#x1006;
                                            span 删除
        .row(style='padding:5px;')
            .col-lg-12#page(style='text-align:center;')
    script.
        $(document).ready(function () {
            $('#batdel').click(function () {
                var ids = "";
                $('.ids').each(function () {
                    if ($(this).prop("checked")) {
                        if (ids != "") {
                            ids += "&";
                        }
                        ids += "ids=" + $(this).val();
                    }
                });
                $('#batdel').attr('href', '/admin/metadata/batdelete.html?' + ids);

            });

        });
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage
                , layer = layui.layer;

            var msg = "#{msg}";
            if (msg) top.layer.msg(msg);

            laypage({
                cont: 'page'
                // ,pages: <#if metadataList??>${metadataList.totalPages}<#else>0</#if> //总页数
                // ,curr:<#if metadataList??>${metadataList.number+1}<#else>0</#if>
                , groups: 5 //连续显示分页数
                , jump: function (data, first) {
                    if (!first) {
                        location.href = "/admin/metadata/index.html?p=" + data.curr;
                    }
                }
            });
        });

